﻿<div class="row-fluid page-content">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <div class="page-head-line location">
                    <span>位置：</span>
                    <ul>
                        <li><a href="/">首页</a></li>
                        <li>业务管理</li>
                        <li>结算统计</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div id="toolbar">
                    <div>
                        <div class="form-inline" role="form">
                            <div class="form-group col-md-3">
                                <div class="input-group">
                                    <span class="input-group-addon">人员姓名: </span>
                                    <input name="CrewName" type="text" class="form-control query-CrewName" />
                                </div>
                            </div>
                            <div class="form-group col-md-3">
                                <div class="input-group">
                                    <span class="input-group-addon">结束时间Begin: </span>
                                    <input name="Start" type="text" class="form-control date query-Start" />
                                </div>
                            </div>
                            <div class="form-group col-md-3">
                                <div class="input-group">
                                    <span class="input-group-addon">结束时间End</span>
                                    <input name="End" type="text" class="form-control date query-End" />
                                </div>
                            </div>
                            <div class="form-group col-md-3">
                                <div class="input-group">
                                    <span class="input-group-addon">服务类别: </span>
                                    <select name="Category" class="form-control query-Category"></select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div class="form-inline" role="form">
                            <div class="form-group col-md-2">
                                <div class="input-group">
                                    <span class="input-group-addon">所属公司: </span>
                                    <select name="Company" class="form-control query-Company">
                                        <option value="" selected="selected">所有</option>
                                        <option>珅昕</option>
                                        <option>复医</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-2">
                                <div class="input-group">
                                    <span class="input-group-addon">人员性质: </span>
                                    <select name="CrewType" class="form-control query-CrewType"></select>
                                </div>
                            </div>
                            <div class="form-group col-md-2">
                                <div class="input-group">
                                    <span class="input-group-addon">班次: </span>
                                    <select name="Shift" class="form-control query-Shift">
                                        <option value="-1" selected="selected">所有</option>
                                        <option value="0">全天</option>
                                        <option value="1">白班</option>
                                        <option value="2">夜班</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-2">
                                <div class="input-group">
                                    <span class="input-group-addon">结算标识: </span>
                                    <select name="OnlySettle" class="form-control query-OnlySettle">
                                        <option value="0" selected="selected">所有</option>
                                        <option value="1">已结算</option>
                                        <option value="2">未结算</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="input-group">
                                    <button class="query btn btn-primary"><i class="fa fa-search fa-lg"></i>查 询</button>
                                    <button class="export btn btn-default"><span class="export"></span> 导 出</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <table id="wageViewTable" class="myTable"></table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("input.date").datepicker({
        changeYear: true,
        showButtonPanel: true
    });
    $("input.datetime").datetimepicker({
        changeYear: true,
        showButtonPanel: true,
        hour: 8
    });
    //时间初始化
    $("#toolbar input[name='Start']").val($.getDate(0, -1));
    $("#toolbar input[name='End']").val($.getCurrentDate());

    loadTable();

    function initSelect() {
        //人员性质
        if (window._util.ItemCode.CrewType != null) {
            var htmlStr = "";
            $.each(window._util.ItemCode.CrewType, function (ix, item) {
                htmlStr += '<option value="' + item.Value + '">' + item.Text + '</option>';
            });

            htmlStr = '<option value="" selected="selected">所有</option>' + htmlStr;
            $("#toolbar .query-CrewType").html(htmlStr);
        }
        //服务类别
        if (window._util.ItemCode.ServiceType != null) {
            var htmlStr = "";
            $.each(window._util.ItemCode.ServiceType, function (ix, item) {
                htmlStr += '<option value="' + item.Value + '">' + item.Text + '</option>';
            });

            htmlStr = '<option value="" selected="selected">所有</option>' + htmlStr;
            $("#toolbar .query-Category").html(htmlStr);
        }
    }

    //查询
    $("#page-inner button.query").click(function () {
        $('#wageViewTable').bootstrapTable('refresh');
    });
    //导出
    $("#page-inner button.export").click(function () {
        var crewName = $("#toolbar .query-CrewName").val();
        var customerName = $("#toolbar .query-CustomerName").val();
        var start = $("#toolbar .query-Start").val();
        var end = $("#toolbar .query-End").val();
        var shift = $("#toolbar .query-Shift").val();
        var crewType = $("#toolbar .query-CrewType").val();
        var category = $("#toolbar .query-Category").val();
        var company = $("#toolbar .query-Company").val();
        var receiptType = $("#toolbar .query-ReceiptType").val();
        var onlySettle = $("#toolbar .query-OnlySettle").val();

        var params = "CrewName=" + crewName + "&CustomerName=" + customerName + "&Start=" + start + "&End=" + end + "&Shift=" + shift + "&CrewType=" + crewType + "&Category=" + category + "&Company=" + company + "&ReceiptType=" + receiptType + "&OnlySettle=" + onlySettle;
        $.ajax({
            url: window._util.BASE_URL + "/Export/QueryWage",
            dataType: "json",
            data: params,
            success: function (rep) {
                if (rep.Result) {
                    $.downloadFile(window._util.BASE_URL + '/Export/Download', 'post', rep.Message);
                } else {
                    alert(rep.Message);
                }
            }
        }).fail(function (T, S) {
            alert("浏览器超时未响应，请刷新重试");
        });
        return false;
    });
    function loadTable() {
        initSelect();
        $('#wageViewTable').bootstrapTable({
            url: window._util.BASE_URL + '/Business/QueryWageNew',
            method: 'get',
            dataType: "json",
            cache: true,
            totalField: 'MaxRows',
            dataField: 'Items',
            queryParamsType: "Page",
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            singleSelect: true,
            pagination: false, //分页
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 20, 50, 100, 200, 500],        //可供选择的每页的行数（*）
            search: false, //显示搜索框
            sidePagination: "server", //服务端处理分页
            clickToSelect: true,                //是否启用点击选中行
            showRefresh: false,                  //是否显示刷新按钮
            showFooter: true,
            queryParams: function (params) {
                params["Start"] = $("#toolbar .query-Start").val();
                params["End"] = $("#toolbar .query-End").val();
                params["Category"] = $("#toolbar .query-Category").val();
                params["Company"] = $("#toolbar .query-Company").val();
                params["CrewName"] = $("#toolbar .query-CrewName").val();
                params["CrewType"] = $("#toolbar .query-CrewType").val();
                params["Shift"] = $("#toolbar .query-Shift").val();
                params["OnlySettle"] = $("#toolbar .query-OnlySettle").val();

                return params;
            },
            columns: [
                {
                    field: 'Id',
                    title: '人员编号',
                    align: 'center',
                    hlign: 'center',
                    footerFormatter: function (value) {
                        return '合计';
                    }
                },
                {
                    field: 'Name',
                    title: '人员姓名',
                    align: 'center',
                    hlign: 'center'
                },
                {
                    field: 'DayCount',
                    title: '出勤天数',
                    align: 'center',
                    hlign: 'center',
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            sum += value[i].DayCount;
                        }
                        return sum.toString();
                    }
                },
                {
                    field: 'CustomerCount',
                    title: '服务人数',
                    align: 'center',
                    hlign: 'center',
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            sum += value[i].CustomerCount;
                        }
                        return sum.toString();
                    }
                },
                {
                    field: 'Adjust',
                    title: '调整合计',
                    align: 'center',
                    hlign: 'center',
                    formatter: function (value, row, index) {
                        if (row.Adjust == null || row.Adjust.length == 0) {
                            return 0;
                        } else {
                            return row.Adjust;
                        }
                    },
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if (value[i].Adjust != null) {
                                sum += value[i].Adjust;
                            }
                        }
                        return sum.toString();
                    }
                },
                {
                    field: 'Pay',
                    title: '结算款合计',
                    align: 'center',
                    hlign: 'center',
                    formatter: function (value, row, index) {
                        if (row.Pay == null || row.Pay.length > 0) {
                            return 0;
                        } else {
                            return row.Pay;
                        }
                    },
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if (value[i].Pay != null) {
                                sum += value[i].Pay;
                            }
                        }
                        return sum.toString();
                    }
                },
                {
                    field: 'Bonus',
                    title: '奖惩合计',
                    align: 'center',
                    hlign: 'center',
                    formatter: function (value, row, index) {
                        if (row.Bonus == null || row.Bonus.length == 0) {
                            return 0;
                        } else {
                            return row.Bonus;
                        }
                    },
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if (value[i].Bonus != null) {
                                sum += value[i].Bonus;
                            }
                        }
                        return sum.toString();
                    }
                },
                {
                    title: '实发合计',
                    align: 'center',
                    hlign: 'center',
                    formatter: function (value, row, index) {
                        var sum = 0;
                        if (row.Pay == null || row.Pay.length == 0) {
                            sum += 0;
                        } else {
                            sum += row.Pay;
                        }
                        if (row.Bonus == null || row.Bonus.length == 0) {
                            sum += 0;
                        } else {
                            sum += row.Bonus;
                        }

                        return sum;
                    },
                    footerFormatter: function (value) {
                        var sum = 0;
                        for (var i in value) {
                            if (value[i].Pay != null) {
                                sum += value[i].Pay;
                            }
                            if (value[i].Bonus != null) {
                                sum += value[i].Bonus;
                            }
                        }
                        return sum.toString();
                    }
                },
                {
                    field: 'Note',
                    title: '签收',
                    align: 'center',
                    hlign: 'center'
                },
                {
                    field: 'Note',
                    title: '备注',
                    align: 'center',
                    hlign: 'center'
                }

            ]
        });
    }
</script>